package com.punai.file.controller;

import com.punai.common.annotation.Log;
import com.punai.common.core.controller.BaseController;
import com.punai.common.core.domain.AjaxResult;
import com.punai.common.enums.BusinessType;
import com.punai.file.service.UploadFileService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

@RestController
@RequestMapping("/file")
public class UploadFileController extends BaseController {

    @Autowired
    private UploadFileService uploadFileService;

    @Log(title = "数据导入", businessType = BusinessType.INSERT)
    @PostMapping("/uploadFile")
    public AjaxResult uploadFile(MultipartFile file)
    {
        String fileId = uploadFileService.disposeFile(file,getCompanyId());
        return AjaxResult.success("上传成功!",fileId);
    }

    @Log(title = "数据导入", businessType = BusinessType.INSERT)
    @DeleteMapping("/delFile/{id}")
    public AjaxResult delFile(@PathVariable String id)
    {
        return toAjax(uploadFileService.delFile(id, getCompanyId()));
    }
}
